// component/common/com-pick-house-item/com-pick-house-item.js
import { houseInfoBehavior } from "../../../behaviors/houseInfo";

Component({
  behaviors: [houseInfoBehavior],

  /**
   * 组件的属性列表
   */
  properties: {
    model: {
      type: Object,
      value: {},
    },
  },

  options: {
    styleIsolation: "apply-shared",
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    _model: {},
    selected: false,
  },

  lifetimes: {
    attached: function () {
      let model = this.data.model;
      let result = { ...model };
      result.delegationType = result.delegationType || "SALES"
      result.totalPrices = this.getPriceText(result)
      result.room = result.room ? result.room + "室" : "";
      result.hall = result.hall ? result.hall + "厅" : "";
      result.room_hall = result.room + result.hall;
      result.room_hall = result.room_hall ? result.room_hall : "未填户型";
      result.buildSize = result.buildSize != -1 && result.buildSize ? result.buildSize + "㎡" : "未填面积";
      result.filePath = result.filePath || "/images/defaultImgSmall.jpg";
      result.area = result.area || ""
      result.addr = result.addr || ""
      result.area_addr = (!result.area && !result.addr) ? '暂无地址' : result.area + " " +result.addr;

      this.setData({
        _model: result,
      });
    },
    
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleSelect() {
      this.setData({
        selected: !this.data.selected
      })

      this.triggerEvent('onselectchange', {id: this.data._model.hmDelId, select: this.data.selected})
    },
  },
});
